package com.marcocirillo.justweet;

import javax.swing.*;
import java.awt.*;

public class LoginWindow extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2261387331524212426L;
	private JLabel usernameLabel;
	private JLabel passwordLabel;
	private JTextField usernameText;
	private JPasswordField passwordText;
	private JButton loginButton;
	private JPanel usernamePanel;
	private JPanel passwordPanel;
	private JPanel loginPanel;
	private JusTweet jt;
	//private GUI gui;
	
	public static final String USERNAME_TEXT = "Username: ";
	public static final String PASSWORD_TEXT = "Password: ";
	public static final String LOGIN_TEXT = "Login";
	public static final String TITLE_TEXT = "Please Enter Login Information";
	
	public LoginWindow(int width, int height, JusTweet jt)
	{
		/* Construct Window */
		super(TITLE_TEXT);
		super.setSize(width, height);
		super.setDefaultCloseOperation(EXIT_ON_CLOSE);
		super.setLayout(new GridLayout(0,1));
		this.jt = jt;
		//this.gui = gui;
		
	    try {
	        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
	    } catch (Exception evt) {}
		
		/* Construct Panels  */
	    usernamePanel = new JPanel(new FlowLayout());
	    passwordPanel = new JPanel(new FlowLayout());
	    loginPanel = new JPanel(new FlowLayout());
	    
	    /* Construct Widgets */
	    usernameLabel = new JLabel(LoginWindow.USERNAME_TEXT);
	    usernameText = new JTextField("", 30);
	    passwordLabel = new JLabel(LoginWindow.PASSWORD_TEXT);
	    passwordText = new JPasswordField ("", 30);
		passwordText.setEchoChar('*');
	    loginButton = new JButton(LOGIN_TEXT);
	    
	    /* Add ActionListeners */
	    loginButton.addActionListener(new Controller(this.jt, this));
	    loginButton.setActionCommand(LOGIN_TEXT);
	    
	    /* Pack Window */
	    usernamePanel.add(usernameLabel);
	    usernamePanel.add(usernameText);
	    passwordPanel.add(passwordLabel);
	    passwordPanel.add(passwordText);
	    loginPanel.add(loginButton);
	    this.add(usernamePanel);
	    this.add(passwordPanel);
	    this.add(loginPanel);
	    this.pack();   
	}
	
	public String getUsernameText()
	{
		return usernameText.getText();
	}
	public String getPasswordText()
	{
		char[] c = passwordText.getPassword();
		String s = new String(c);
		return s;
	}
}
